package com.zjht.gmcc.bean.action;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.zjht.gmcc.bean.util.MyJDBC;

/**
 * 终端接盘相关方法
 * @author dyh 2011-07-14
 */
public class ShiftUtil implements java.io.Serializable {
	private static final long serialVersionUID = 2123158838657051800L;

	/**
	 * 获取畅销程度名称(1-畅销,2-一般,3-滞销,4-集采,5-集采追加,6-暂无销量)
	 * @author dyh 2011-07-17
	 * @param popular
	 * @return 畅销程度名称
	 */
	public static String getPopularName(String popular) {
		String popularName = "";
		if ("1".equals(popular)) {
			popularName = "畅销";
		} else if ("2".equals(popular)) {
			popularName = "一般";
		} else if ("3".equals(popular)) {
			popularName = "滞销";
		} else if ("4".equals(popular)) {
			popularName = "集采";
		} else if ("5".equals(popular)) {
			popularName = "集采追加";
		} else if ("6".equals(popular)) {
			popularName = "暂无销量";
		} else {
			popularName = "";
		}
		return popularName;
	}

	/**
	 * 获取生命周期(1-导入期,2-成长期,3-成熟期,4-衰退期)
	 * @author dyh 2011-07-17
	 * @param life
	 * @return 生命周期名称
	 */
	public static String getLifeName(String life) {
		String lifeName = "";
		if ("1".equals(life)) {
			lifeName = "导入期";
		} else if ("2".equals(life)) {
			lifeName = "成长期";
		} else if ("3".equals(life)) {
			lifeName = "成熟期";
		} else if ("4".equals(life)) {
			lifeName = "衰退期";
		}
		return lifeName;
	}
	
	/**
	 * 如果参数值为负数，则输出“无限制”
	 * @author dyh 2011-07-17
	 * @param para
	 * @return 
	 */
	public static String getUnlimited(int para) {
		return para<0?"无限制":"";
	}
	
	/**
	 * 如果参数值为负数，则输出“全部接收”
	 * @author dyh 2011-07-17
	 * @param para
	 * @return 
	 */
	public static String getAllReceive(int para) {
		return para<0?"全部接收":"";
	}

	/**
	 * 选型相关参数值
	 * @author dyh 2010-06-06
	 * @param flag 选型参数paraid(Parameter表)
	 * @return 是/否
	 */
	public static String getChoiceFlag(int flag) {
		String status = "";// CHOICE_NOT_STARTED;
		if (flag > 0) {
			MyJDBC myJDBC = null;
			try {
				myJDBC = new MyJDBC();
				String strSQL = "SELECT status FROM Parameter WHERE paraid=?";
				PreparedStatement ps = myJDBC.prepareStatement(strSQL);
				ps.setInt(1, flag);
				ResultSet rs = ps.executeQuery();
				if (rs.next()) {
					status = rs.getString(1);
				}
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				MyJDBC.close(myJDBC);
			}
		}
		return status;
	}
}